<template>
  <div class="tabs-container">
    <div class="tabs-navigation">
      <div
        v-for="(tab, index) in tabs"
        :key="index"
        :class="['tab-item', { active: selectedTab === index }]"
        @click="selectTab(tab, index)"
      >
        {{ tab.name }}
      </div>
    </div>
    <!-- <div class="active-indicator" :style="indicatorStyle"></div> -->
    <div class="tabs-content">
      <component v-if="currentTabComponent" :is="currentTabComponent"></component>

      <div class="empty" v-else>
        <img src="@/assets/imgs/empty.webp" class="empty-icons" />
        <p>暂无数据</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, markRaw } from 'vue'
import TechStatsModule from '@/views/match-detail/basketballComponents/BasketballStats.vue'
import PlayerStats from '@/views/match-detail/basketballComponents/BasketballPlayerStats.vue'
import TextLive from '@/views/match-detail/basketballComponents/BasketballTextLive.vue'
// import ExponentLive from '@/views/match-detail/basketballComponents/BasketballExponentLive.vue'
import Lineup from '@/views/match-detail/basketballComponents/BasketballLineup.vue'
import OddsLive from '@/views/match-detail/basketballComponents/BasketballOddsLive.vue'
import DataAnalysis from '@/views/match-detail/basketballComponents/DataAnalysis/index.vue'

const tabs = [
  { name: '文字直播', key: markRaw(TextLive) },
  { name: '出场阵容', key: markRaw(Lineup) },
  { name: '球队统计', key: markRaw(TechStatsModule) },
  { name: '球员统计', key: markRaw(PlayerStats) },
  { name: '数据分析', key: markRaw(DataAnalysis) },
  { name: '指数直播', key: markRaw(OddsLive) }
]

const selectedTab = ref(0)

const selectTab = (item, index) => {
  selectedTab.value = index
}

const currentTabComponent = computed(() => {
  return tabs[selectedTab.value].key || false
})

const indicatorStyle = computed(() => {
  const tabWidth = 30 / tabs.length
  return {
    width: `${tabWidth}%`,
    left: `${tabWidth * selectedTab.value + 4 * selectedTab.value}%`
  }
})
</script>

<style scoped lang="scss">
.tabs-container {
  background-color: #fff;

  border-radius: 10px;
  overflow: hidden;
}
.tabs-navigation {
  display: flex;
  justify-content: space-around;
  align-items: center;
  font-family: Arial, sans-serif;
  border-bottom: 1px solid #e0e0e0;

  .tab-item {
    font-size: 16px;
    color: #666;
    cursor: pointer;
    padding: 20px 0;

    &.active {
      font-size: 16px;
      color: #16b13a;
      font-weight: bold;
      border-bottom: 2px solid #16b13a;
    }
  }
}

.active-indicator {
  height: 2px;
  background-color: #1e90ff;
  position: relative;
  transition: left 0.3s ease;
  left: 50%;
}
.tabs-content {
  min-height: 648px;
  width: 100%;
  .empty {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-weight: 400;
    font-size: 14px;
    color: #afb8cb;
    .empty-icons {
      width: 300px;
      height: 300px;
      // margin-bottom: 20px;
    }
  }
}
</style>
